#include <iostream>
#include <string>
#include <vector>

int main() {
    std::string thr_chsl;
    std::vector<std::string> lst_frm_thr_chsl;
    std::vector<std::string> spsk_int_frm = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    std::vector<std::string> spsk_wrd_frm = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int fl_nmb = 0;

    std::cin >> thr_chsl;
    lst_frm_thr_chsl = split(thr_chsl);

    while (true) {
        if (lst_frm_thr_chsl[0] == "zero" || lst_frm_thr_chsl.size() != 3) {
            std::cout << "Wrong input" << std::endl;
            break;
        }

        bool wrong_input = false;
        for (int i = 0; i < 3; i++) {
            if (lst_frm_thr_chsl[i].length() < 3) {
                std::cout << "Wrong input" << std::endl;
                wrong_input = true;
                break;
            }
        }

        if (wrong_input) {
            break;
        }

        fl_nmb = std::stoi(spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[0])] + spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[1])] + spsk_int_frm[spsk_wrd_frm.index(lst_frm_thr_chsl[2])]);
        break;
    }

    int prst_chsl_pls = fl_nmb;
    int prst_chsl_mns = fl_nmb;
    int razn_pls = 0;
    int razn_mns = 0;
    int razn2p = 1;
    int razn2m = 1;
    int fns_raz_pls = 0;
    int fns_raz_mns = 0;
    int deli_fn_pls = 2;
    int deli_fn_mns = 2;

    while (razn2p != 0) {
        while (deli_fn_pls != prst_chsl_pls - 1) {
            if (prst_chsl_pls % deli_fn_pls == 0) {
                razn_pls += 1;
            }
            deli_fn_pls += 1;

            if (razn_pls > 0) {
                prst_chsl_pls += 1;
                deli_fn_pls += 1;
                razn_pls = 0;
                razn2p += 1;
                fns_raz_pls = razn2p - 1;
            }

            if (deli_fn_pls == prst_chsl_pls - 2 && razn_pls == 0) {
                razn2p = 0;
            }
        }
    }

    while (razn2m != 0) {
        while (deli_fn_mns != prst_chsl_mns - 1) {
            if (prst_chsl_mns % deli_fn_mns == 0) {
                razn_mns += 1;
            }
            deli_fn_mns += 1;

            if (razn_mns > 0) {
                prst_chsl_mns -= 1;
                deli_fn_mns = 2;
                razn_mns = 0;
                razn2m += 1;
                fns_raz_mns = razn2m - 1;
            }

            if (deli_fn_mns == prst_chsl_mns - 2 && razn_mns == 0) {
                razn2m = 0;
            }
        }
    }

    if (fns_raz_mns > fns_raz_pls) {
        std::cout << prst_chsl_pls << std::endl;
    }

    if (fns_raz_mns < fns_raz_pls) {
        std::cout << prst_chsl_mns << std::endl;
    }

    if (fns_raz_mns == fns_raz_pls) {
        std::cout << prst_chsl_mns << std::endl;
    }

    return 0;
}
